﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WorkFlowBLL;

namespace QLCF.Forms
{
    public partial class popupEditQuantification : Form
    {
        public popupEditQuantification()
        {
            InitializeComponent();
        }
        private frmQuantification frmQuantificationCall;
        private int QuantifiID = -1;
        private float oldQuan = 0;
        public popupEditQuantification(frmQuantification m_frmQuantification,int m_QuantifiID,string pName, float quantity, string unit)
        {
            InitializeComponent();
            frmQuantificationCall = m_frmQuantification;
            lblProductName.Text = pName;
            numQuantify.Value = (decimal)quantity;
            lblUnit.Text = unit;
            QuantifiID = m_QuantifiID;
            oldQuan = quantity;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if(numQuantify.Value<=0)
            {
                MessageBox.Show("Bạn chưa nhập định lượng");
                numQuantify.Focus();
                return;
            }
            CtrProduct ctrP = new CtrProduct();
            if (ctrP.QuantificationSetQuantity(QuantifiID, Convert.ToDouble(numQuantify.Value))>0)
            {
                if ((decimal)oldQuan != numQuantify.Value)
                {
                    CtrAdmin ctra = new CtrAdmin();
                    ctra.LogInsert(Program.UserEntity.UserID, Program.UserEntity.UserName, 2, "Sửa định lượng \"" + oldQuan + " -> " + numQuantify.Value + "\" sản phẩm \"" + lblProductName.Text + "\"", "Định lượng");
                }
                frmQuantificationCall.UpdateQuantity(numQuantify.Value + " " + lblUnit.Text);
                this.Close();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
